<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>1-Promise基本语法</title>
</head>

<body>
    <script>
        //实例化Promise对象
        //p有三个状态,初始化,成功,失败
        const p = new Promise(function (resolve, reject) {
            setTimeout(function () {
                let data = '123';
                //调用resolve后p的状态是成功,then执行第一个函数
                //resolve(data);

                //调用reject后p的状态是失败,then执行第二个函数
                let err = '读取失败'
                reject(err);
            }, 1000);
        });
        //调用promise对象的then
        p.then(function (value) {
            console.log(value);
        }, function (reason) {
            console.log(reason);
        });
    </script>

</body>

</html>